///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_MAT_PRETTYPRINT_H_
#define _BUOLA_MAT_PRETTYPRINT_H_

#include <buola/mat/cexpr.h>

namespace buola { namespace mat {

template<typename tSub>
inline io::CTextWriter &operator<<(io::CTextWriter &pWriter,const detail::CNameOp<tSub> &pExpr)
{
    const auto &lSub=detail::element_accessible<detail::ACCESS_ONCE>(pExpr.Sub());

    int lPreWidth=pExpr.Name().length()+3;
    std::string lPre(lPreWidth,' ');
    int lNumWidth=1+7*lSub.Cols();
    std::string lNum(lNumWidth,' ');

    pWriter << lPre << "\u250C" << lNum << "\u2510\n";

    for(int i=0;i<lSub.Rows();i++)
    {
        if(i==lSub.Rows()/2)
            pWriter << pExpr.Name() << " = ";
        else
            pWriter << lPre;
        pWriter << "\u2502";
        for(int j=0;j<lSub.Cols();j++)
        {
            pWriter << " " << std::to_string(lSub(i,j),6);
        }
        pWriter << " \u2502";
        pWriter << "\n";
    }

    pWriter << lPre << "\u2514" << lNum << "\u2518\n";

    return pWriter;
}

/*namespace mat*/ } /*namespace buola*/ }

#endif
